#!/bin/bash

fixed=192.168.1.
start=1
end=255

if [[ $# -eq 3 ]];
then
  fixed=$1
  start=$2
  end=$3
else
  echo -e "参数1：固定部分"
  echo -e "参数2：开始"
  echo -e "参数3：结束"
  exit 0
fi

for ((i=$start;i<=$end;i++));
  do
    echo -e "check: $fixed$i \c"
    ping -c 1 -w 1 "$fixed$i"  > /dev/null; 
    if [ $? -eq 0 ]; then
      echo -e "ok"
      # echo "$fixed$i" >> act.txt;
    else
      echo -e "err"
      # echo "$fixed$i" >> na.txt;
    fi;
  done;
